#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> shortestDistanceAfterQueries(int n, vector<vector<int>>& queries) {
        vector<int> roads(n);
        for (int i = 0; i < n - 1; i++)roads[i] = i + 1;
        vector<int> res;
        int move = n - 1;
        for (auto& vec : queries)
        {
            int k = roads[vec[0]];
            while (k != -1 && k < vec[1])
            {
                roads[vec[0]] = vec[1];
                int next = roads[k];
                roads[k] = -1;
                k = next;
                --move;
            }
            cout << endl;
            res.push_back(move);
        }
        return res;
    }
};